package cn.pengyinrui.pethome.base.service.impl;

import cn.pengyinrui.pethome.base.mapper.BaseMapper;
import cn.pengyinrui.pethome.base.query.BaseQuery;
import cn.pengyinrui.pethome.base.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public T findOne(Long id) {
        return mapper.findOne(id);
    }

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    public List<T> findAllByQuery(BaseQuery query) {
        return mapper.findAllByQuery(query);
    }

    @Override
    public Long findAllByQueryCount(BaseQuery query) {
        return mapper.findAllByQueryCount(query);
    }

    @Override
    @Transactional
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    @Transactional
    public void batchDel(List ids) {
        mapper.batchDel(ids);
    }
}
